package com.abyss.source;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.NumberSequenceIterator;

/**
 * 基于本地集合构建可以并行的Source
 */
public class BasicSourceWithParallelDemo {
    public static void main(String[] args) throws Exception {
        // 1. Env
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 2.1 构建一个序列 可并行
        DataStreamSource<Long> seqSource = env.generateSequence(1, 10).setParallelism(6);

        // 2.2 构建一个可并行的 从集合获取的Source
        DataStreamSource<Long> seq2Source = env.fromParallelCollection(new NumberSequenceIterator(100, 110),Long.TYPE);

        // 3.数据处理略
        // 4. Sink
        seq2Source.print();

        // 5. 提交任务
        env.execute();
    }
}
